import tornado.ioloop,time
import tornado.websocket
import asyncio
t=time.time()
class Client:
    def on_message(self, message):
        pass
        # print(f"Server said: {message}")

    async def send_messages(self, count):
        ws_url = "ws://localhost:8888/ws"
        websocket = await tornado.websocket.websocket_connect(ws_url)
        for i in range(count):
            await websocket.write_message(f"Message {i}")
            response = await websocket.read_message()
            if response is None:
                break
            self.on_message(response)
        await websocket.close()

async def main():
    client = Client()
    await client.send_messages(100000)  # 发送10万条消息

if __name__ == "__main__":
    asyncio.run(main())